from collections import OrderedDict

from django.shortcuts import render

from web import models


def device_query_list(request):
    queryset = models.Device.objects.filter(active=1).order_by('title')
    data_dict = OrderedDict()

    data_dict = {item.title: [] for item in models.DeviceType.objects.all().order_by('title')}

    for item in queryset:
        data_dict[item.device_type.title].append(item)

    return render(request, 'device_query_list.html', {'data_dict': data_dict})
